#include <iostream>
#include <iterator>
#include <algorithm> 
#include <boost/lambda/lambda.hpp> 
#include <boost/lambda/if.hpp>
#include <boost/filesystem.hpp>
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
#include <sstream>

using namespace std;
namespace boostDemo
{
    

    template<class T> class A {
    public:
        T g(T a, T b);
        A();
    };
    template<class T> A<T>::A() {}

    template<class T> T A<T>::g(T a, T b) {
        return a + b;
    }

    void main() {

        stringstream ss;

        boost::scoped_ptr<int> i(new int);
        *i = 1;
        ss << *i << endl;
        *i.get() = 2;
        ss << *i << endl;
        i.reset(new int);
        ss << *i << endl;

        ss.str("scoped_ptr demo end.\n");

        A<int> a;
        ss << a.g(2, 3.2) << endl;

        A<float> b;
        ss << b.g(1.01, 2.02) << endl;
        ss<< ("template demo end.\n");

        cout<<ss.str();
        using namespace boost::lambda;

        std::vector<int> v;
        v.push_back(1);
        v.push_back(3);
        v.push_back(2);

        std::for_each(v.begin(), v.end(), ss << boost::lambda::_1 << "\n");

        cout<<ss.str();
        ss.str("");
        std::for_each(v.begin(), v.end(),
            boost::lambda::if_then(boost::lambda::_1 > 1,
                ss << boost::lambda::_1 << "\n"));

        cout<<ss.str();
        ss.str("");
        using namespace boost::filesystem;
#define FileNameImgBox "boostLearn.exe"
//        ss << FileNameImgBox << " " << file_size(FileNameImgBox) << std::endl;

        boost::scoped_array<int> ary(new int[2]);
        *ary.get() = 1;
        ary[1] = 2;
        ary.reset(new int[3]);

        typedef std::istream_iterator<int> in;
        std::for_each(
            in(std::cin), in(), ss << (_1 * 3) << " ");

    }
    
}
